//获取应用实例
var app = getApp()
Page({
  data: {
    approveId:"",
    approve:"",
    status:""
  },

  onLoad: function (options) {
    this.setData({
      approveId: options.approveId,
    })
    this.getApprove()
  },

  getApprove: function () {
    var that = this
    if (this.data.approveId != "") {
      wx.request({
        url: 'https://eis.natappvip.cc/ITSupport/approve_getApproveById.action',
        data: {
          'approve.approveId': this.data.approveId,
        },
        header: {
          'Content-Type': 'application/json'
        },
        success: function (res) {
          let jsonresult = JSON.parse(res.data)
          console.log(jsonresult.result)
          if (jsonresult.result == "success") {
            that.setData({
              approve: jsonresult.approve,
            })
          }
        },
        fail: function (res) {
          console.log("failed:" & res)
        }
      })
    }
  },

  pass: function (e) {
    this.setData({
      status: "审核通过"
    })
    this.updateApprove()
  },

  reject: function (e) {
    this.setData({
      status: "驳回"
    })
    this.updateApprove()
  },

  updateApprove: function () {
    var that = this
    if (this.data.status != "") {
      wx.request({
        url: 'https://eis.natappvip.cc/ITSupport/approve_updateApprove.action',
        data: {
          'approve.approveId': this.data.approveId,
          'approve.status': this.data.status,
          'user.userId': this.data.approve.topic.userByUserId.userId
        },
        header: {
          "content-type": "application/x-www-form-urlencoded"
        },
        success: function (res) {
          let jsonresult = JSON.parse(res.data)
          console.log(jsonresult.result)
          if (jsonresult.result == "success") {
            wx.showModal({
              title: '提示',
              content: '审核成功,是否返回用户动态？',
              success: function (res) {
                if (res.confirm) {
                  wx.navigateBack({
                    delta: 1
                  })
                }
              }
            })
          }
        },
        fail: function (res) {
          console.log("failed:" & res)
        }
      })
    }
  },

})
